package com.example.demo.service;

import com.example.demo.entity.Music;
import com.example.demo.entity.NoteCreate;
import com.example.demo.mapper.NoteCreateMapper;
import com.example.demo.vo.ViewNoteCommentInfo;
import com.example.demo.vo.ViewNoteCreateInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteCreateImpl implements NoteCreateService {

    @Autowired
    private NoteCreateMapper noteCreateMapper;

    //实现分页功能
    @Override
    public PageInfo<NoteCreate> findNoteCreatePages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize); //分页配置,有一页，每页数据为3条，第一页的3条数据
        List<NoteCreate> lists = noteCreateMapper.findNoteCreateAll();
        PageInfo<NoteCreate> pageInfo = new PageInfo<>(lists);  //构造函数，传递函数
        return pageInfo;   //返回pageInfo
    }

//    @Override
//    public PageInfo<ViewNoteCreateInfo> findNoteCreateInfo(Integer pageNum, Integer pageSize) {
//        PageHelper.startPage(pageNum, pageSize);
//        List<ViewNoteCreateInfo> list = noteCreateMapper.findNoteCreateInfo();
//        PageInfo<ViewNoteCreateInfo> pageInfo = new PageInfo<>(list);
//        return pageInfo;
//    }

    @Override
    public List<NoteCreate> findNoteCreateByview_count() {
        return noteCreateMapper.findNoteCreateByview_count(); // 使用注入的实例调用方法
    }

    //根据笔记状态查找筛选数据
    //根据笔记状态查找筛选数据
    @Override
    public PageInfo<ViewNoteCreateInfo> findNoteCreateInfostatus(Integer pageNum, Integer pageSize,String note_status) {
        PageHelper.startPage(pageNum, pageSize);
        List<ViewNoteCreateInfo> list = noteCreateMapper.findNoteCreateInfostatus(note_status);
        PageInfo<ViewNoteCreateInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //笔记表和用户表关联：获取用户名以及用户头像
    @Override
    public PageInfo<ViewNoteCreateInfo> findNoteCreateInfouser() {
//        PageHelper.startPage();
        List<ViewNoteCreateInfo> list = noteCreateMapper.findNoteCreateInfouser();
        PageInfo<ViewNoteCreateInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    //笔记信息与用户信息相关联（不分页）,获取用户所有信息
    @Override
    public PageInfo<ViewNoteCreateInfo> findNoteCreateUserId(Integer note_create_id) {
        List<ViewNoteCreateInfo> list = noteCreateMapper.findNoteCreateUserId(note_create_id);
        PageInfo<ViewNoteCreateInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    @Override
    public List<NoteCreate> findNoteCreateAll(){
        return noteCreateMapper.findNoteCreateAll();
    }
    //审核通过
    @Override
    public Integer updateNoteStatusyes(NoteCreate noteCreate) {
        return noteCreateMapper.updateNoteStatus1(noteCreate);
    }

    //审核未通过
    @Override
    public Integer updateNoteStatusno(NoteCreate noteCreate) {
        return noteCreateMapper.updateNoteStatus2(noteCreate);
    }

    //笔记状态待审核
    @Override
    public Integer updateNoteStatusReview(NoteCreate noteCreate) {
        return noteCreateMapper.updateNoteStatus3(noteCreate);
    }

    @Override
    public Integer updateNoteStatus(Integer note_create_id, String note_status) {
        return noteCreateMapper.updateNoteStatus(note_create_id, note_status);
    }


    //根据笔记ID查找
    @Override
    public ViewNoteCreateInfo findNoteCreateinfoDyId(Integer note_create_id){
        return noteCreateMapper.findNoteCreateinfoId(note_create_id);
    }

    //根据用户id和笔记状态查找
    @Override
    public PageInfo<ViewNoteCreateInfo> findNoteCreateInfo( String note_status, Integer user_id) {
//        PageHelper.startPage(pageNum, pageSize);
        List<ViewNoteCreateInfo> list = noteCreateMapper.findNoteCreateinfoByStatusAndUser(note_status, user_id);
        PageInfo<ViewNoteCreateInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public NoteCreate findNoteCreateDyId(Integer note_create_id){
        return noteCreateMapper.findNoteCreateDyId(note_create_id);
    }

    @Override
    public Integer insertNoteCreate(NoteCreate noteCreate){
        return noteCreateMapper.insertNoteCreate(noteCreate);
    }

    @Override
    public Integer updateNoteCreate(NoteCreate noteCreate){
        return noteCreateMapper.updateNoteCreate(noteCreate);
    }

    //修改笔记内容
    @Override
    public Integer updateNoteCreate1(NoteCreate noteCreate){
        return noteCreateMapper.updateNoteCreate1(noteCreate);
    }

    @Override
    public Integer deleteNoteCreate(Integer note_create_id){
        return noteCreateMapper.deleteNoteCreate(note_create_id);
    }

    //根据笔记状态和用户ID计数
    @Override
    public Integer countPublishedNotesByStatus( String note_status, Integer user_id) {
        return noteCreateMapper.countPublishedNotesByStatus(note_status, user_id);
    }

    //点击量
    @Override
    public Integer incrementViewCount(Integer note_create_id) {
        return noteCreateMapper.incrementViewCount(note_create_id);
    }
}
